<?php
$content= file_get_contents('http://php.net');
$dom = new DOMDocument();

////使用tidy规范网页中不规范的内容,否则可能导致document出错
//$tidy     = new tidy;
//$content = $tidy->repairString($content);
////使用utf-8编码
//$content = mb_convert_encoding($content, 'UTF-8');
$dom->loadHTML();


$xpath = new DOMXPAth($document);
//选择要查找的id
$elements = $xpath->query("//*[@id='intro']");

if (!is_null($elements)) {
    foreach ($elements as $element) {
        echo "[". $element->nodeName. "]";
    }
}
?>